import React from "react";
import {
Keyboard,
Pressable,
Text,
TouchableWithoutFeedback,
View,
} from "react-native";
import Animated, {
useAnimatedKeyboard,
useAnimatedStyle,
} from "react-native-reanimated";
import { router, Stack, useLocalSearchParams } from "expo-router";
import TagPill from "@/components/bookmarks/TagPill";
import FullPageError from "@/components/FullPageError";
import FullPageSpinner from "@/components/ui/FullPageSpinner";
import { Input } from "@/components/ui/Input";
import { Skeleton } from "@/components/ui/Skeleton";
import { ChevronRight } from "lucide-react-native";
import {
useAutoRefreshingBookmarkQuery,
useUpdateBookmark,
} from "@hoarder/shared-react/hooks/bookmarks";
import { isBookmarkStillTagging } from "@hoarder/shared-react/utils/bookmarkUtils";
import { BookmarkTypes, ZBookmark } from "@hoarder/shared/types/bookmarks";
function TagList({ bookmark }: { bookmark: ZBookmark }) {
return (
Tags
{isBookmarkStillTagging(bookmark) ? (
) : bookmark.tags.length > 0 ? (
{bookmark.tags.map((t) => (
))}
) : (
No tags
)}
router.push(`/dashboard/bookmarks/${bookmark.id}/manage_tags`)
}
className="flex w-full flex-row justify-between gap-3 rounded-lg bg-white px-4 py-2 dark:bg-accent"
>
Manage Tags
);
}
function ManageLists({ bookmark }: { bookmark: ZBookmark }) {
return (
Lists
router.push(`/dashboard/bookmarks/${bookmark.id}/manage_lists`)
}
className="flex w-full flex-row justify-between gap-3 rounded-lg bg-white px-4 py-2 dark:bg-accent"
>
Manage Lists
);
}
function TitleEditor({
bookmarkId,
title,
}: {
bookmarkId: string;
title: string;
}) {
const { mutate, isPending } = useUpdateBookmark();
return (
Title
mutate({
bookmarkId,
title: ev.nativeEvent.text ? ev.nativeEvent.text : null,
})
}
defaultValue={title ?? ""}
/>
);
}
function NotesEditor({ bookmark }: { bookmark: ZBookmark }) {
const { mutate, isPending } = useUpdateBookmark();
return (
Notes
mutate({
bookmarkId: bookmark.id,
note: ev.nativeEvent.text,
})
}
defaultValue={bookmark.note ?? ""}
/>
);
}
const ViewBookmarkPage = () => {
const { slug } = useLocalSearchParams();
if (typeof slug !== "string") {
throw new Error("Unexpected param type");
}
const keyboard = useAnimatedKeyboard();
const animatedStyles = useAnimatedStyle(() => ({
marginBottom: keyboard.height.value,
}));
const {
data: bookmark,
isPending,
refetch,
} = useAutoRefreshingBookmarkQuery({ bookmarkId: slug });
if (isPending) {
return ;
}
if (!bookmark) {
return (
refetch()} />
);
}
let title = null;
switch (bookmark.content.type) {
case BookmarkTypes.LINK:
title = bookmark.title ?? bookmark.content.title;
break;
case BookmarkTypes.TEXT:
title = bookmark.title;
break;
case BookmarkTypes.ASSET:
title = bookmark.title ?? bookmark.content.fileName;
break;
}
return (
(
{
if (router.canGoBack()) {
router.back();
} else {
router.replace("dashboard");
}
}}
>
Done
),
}}
/>
);
};
export default ViewBookmarkPage;